<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Logout extends CI_Controller {

	public function Logout(){
		parent::__construct();
		parse_str( $_SERVER['QUERY_STRING'], $_REQUEST );
		$CI = & get_instance();
		$CI->config->load("facebook",TRUE);
		$config = $CI->config->item('facebook');
		$this->load->library('Facebook', $config);
	}

	function index(){
		// Try to get the user's id on Facebook
		$userId = $this->facebook->getUser();
		$user = $this->ion_auth->get_user();

		// If user is not yet authenticated, the id will be null
		if ($userId) {
			try {
				$session = $this->facebook->destroySession();
			} catch (FacebookApiException $e) {
				error_log($e);
			}
		}
		
		if($user){
			$this->ion_auth->logout();
		}
		
		redirect("main");
			
	}

}

?>